package com.hexinfo.dmpro.monitor.controller;

import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.common.base.Page;
import com.hexinfo.dmpro.monitor.model.base.MonitorBaseModel;
import com.hexinfo.dmpro.monitor.service.ClusterWhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author peng
 * @date 2022/2/28 14:09
 */

@RestController
@RequestMapping("/monitor_api/clusterwh")
public class ClusterWhController {

    @Autowired
    private ClusterWhService clusterWhService;

    /**
     * 集群信息管理-分页列表
     * @param page
     * @param monitorBaseModel
     * @return
     */
    @GetMapping(value = "/selCmInfo")
    @AnonymousAccess
    public ResponseEntity<Object> selCmInfo(Page page, MonitorBaseModel monitorBaseModel) {
        return new ResponseEntity<>(clusterWhService.selCmInfo(page, monitorBaseModel), HttpStatus.OK);
    }

    /**
     * 集群信息管理-添加（涉及删除redis缓存）
     * @param map
     * @return
     */
    @PostMapping(value = "/saveCmInfo")
    public ResponseEntity<Object> saveCmInfo(@RequestBody Map map) {
        return new ResponseEntity<>(clusterWhService.saveCmInfo(map), HttpStatus.OK);
    }

    /**
     * 集群信息管理-删除（涉及删除redis缓存）
     * @param ids
     * @return
     */
    @DeleteMapping(value = "/delCmInfo")
    public ResponseEntity<Object> delCmInfo(@RequestBody Set<String> ids) {
        return new ResponseEntity<>(clusterWhService.delCmInfo(ids), HttpStatus.OK);
    }

    /**
     * 集群信息管理-监控状态（涉及删除redis缓存）
     * @param map
     * @return
     */
    @PostMapping(value = "/upMonitorFlag")
    public ResponseEntity<Object> upMonitorFlag(@RequestBody Map map) {
        return new ResponseEntity<>(clusterWhService.upMonitorFlag(map), HttpStatus.OK);
    }

    /**
     * 集群信息管理-集群配置刷新（涉及redis缓存）
     * @param monitorBaseModels
     * @return
     */
    @PostMapping(value = "/refreshCluster")
    public ResponseEntity<Object> refreshCluster(@RequestBody List<MonitorBaseModel> monitorBaseModels) {
        return new ResponseEntity<>(clusterWhService.refreshCluster(monitorBaseModels), HttpStatus.OK);
    }

    @GetMapping(value = "/selUserUnit")
    public ResponseEntity<Object> selUserUnit(MonitorBaseModel monitorBaseModel) {
        return new ResponseEntity<>(clusterWhService.selUserUnit(monitorBaseModel), HttpStatus.OK);
    }

}
